package com.hu.zhcc.shiro.controller.Lixueseng520;

import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.shiro.entity.bo.Lixueseng520.LxsExercise;
import com.hu.zhcc.shiro.service.Lixueseng520.ExerciseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("exercise")
public class ExerciseController {
    @Autowired
    private ExerciseService exerciseService;

    // 查询
    @GetMapping("")
    public Page<LxsExercise> getExerciseList(String encode,Integer offset,Integer limit){
        Map map = new HashMap();
        if (!StringUtils.isBlank(encode)){
            map.put("encode",encode);
        }
        return exerciseService.findExerciseByPrimary(map,offset,limit);
    }
    // 添加
    @PostMapping("add")
    public int saveExercise(@RequestBody LxsExercise exercise){
        exerciseService.insertSelective(exercise);
        exercise.setEncode("YD000"+exercise.getId());
        return exerciseService.insertSelective(exercise);
    }
    // 修改
    @PutMapping("/{id}")
    public int getExerciseById(@PathVariable("id") int id,@RequestBody LxsExercise exercise){
        return exerciseService.updateByPrimaryKeySelective(exercise);
    }
    // 删除
    @DeleteMapping("/{id}")
    public int removeExercise(@PathVariable("id") int id){
        return exerciseService.deleteByPrimaryKey(id);
    }
}
